package com.liuhong.shoping.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.liuhong.shoping.dao.UserMapper;
import com.liuhong.shoping.entity.User;
import com.liuhong.shoping.vo.in.Login;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.UUID;

@RestController
public class LoginController {

    @Value("${resources.path.image}")
    String imagePath;

    @Autowired
    UserMapper userMapper;
    @PostMapping("/getUserData/{login}/{pass}")
    public List<User> getUserData(@PathVariable("login") String login, @PathVariable("pass") String pass)
    {

        QueryWrapper<User> queryWrapperUser = new QueryWrapper<>();
//        select * from User
          List<User> list =  userMapper.selectList(null);
//        select id from User where username=#{login}
//        queryWrapperUser.lambda().select(User::getId).eq(User::getUsername,login);
//        select * from User where username = #{login}
//        queryWrapperUser.lambda().eq(User::getUsername,login);
//        select * from User where username=#{login} order by (asc/desc) username
//        queryWrapperUser.lambda().eq(User::getUsername,login).orderByAsc(User::getUsername);
        return list;
    }

    @PostMapping("/login")
    public List<User> login(@RequestBody Login login)
    {
        QueryWrapper<User> queryWrapperUser = new QueryWrapper<>();
        System.out.println(login.toString());
        queryWrapperUser.lambda().select(User::getPassword).eq(User::getUsername,login.getLoginName());
        List<User> list = userMapper.selectList(queryWrapperUser);
        return list;
    }

    @PostMapping("/getPostData")
    public List<User> getPostData(@RequestBody Login login)
    {
        QueryWrapper<User> queryWrapperUser = new QueryWrapper<>();
        System.out.println(login.toString());
        queryWrapperUser.lambda().select(User::getPassword).eq(User::getUsername,login.getLoginName());
        List<User> list = userMapper.selectList(queryWrapperUser);
        return list;
    }
}
